<template>
  <div>
    <!-- --------------------------------搜索框----------------------------- -->
    <div slot="header" class="clearfix">
      <el-form :inline="true" :model="query">
        <el-form-item>
          <el-input v-model="query.receiptOrderNo" placeholder="入库单" :clearable="true"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="query.supplierName" placeholder="供应商" :clearable="true"></el-input>
        </el-form-item>
        <el-form-item>
          <el-date-picker v-model="query.dateRange" type="daterange" range-separator="至" start-placeholder="开始注册日期"
            end-placeholder="结束注册日期" value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="loadReceipts">搜索</el-button>
          <el-button type="success" @click="dialog.addShow = true">新建</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- -----------------------------分页显示数据--------------------------------------- -->
    <el-table :data="receiptList" border style="width: 100%">
      <el-table-column type="index" width="50" label="序号"> </el-table-column>

      <el-table-column prop="receiptOrderNo" label="入库单号" width="220">
      </el-table-column>
      <el-table-column prop="receiptOrderType" label="入库类型" width="130">
      </el-table-column>
      <el-table-column prop="warehouseId" label="仓库序号" width="130">
      </el-table-column>
      <el-table-column prop="supplierName" label="供应商名字" width="130">
      </el-table-column>
      <el-table-column prop="mobileNo" label="供应商电话" width="150">
      </el-table-column>
      <el-table-column prop="updataByName" label="修改人" width="100">
      </el-table-column>
      <el-table-column prop="createTime" label="时间" width="250">
      </el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" size="small" @click="handleEdit(scope.row.id)">编辑</el-button>
          <el-popconfirm title="这是一段内容确定删除吗？" @confirm="handleDelete(scope.row.id)">
            <el-button type="danger" slot="reference" size="small" icon="el-icon-delete">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="query.currentPage" :page-sizes="pageInfo.pageSizes" :page-size="100"
        layout="total, sizes, prev, pager, next, jumper" :total=pageInfo.total>
      </el-pagination>
    </div>
  </div>
</template>
  
<script>
export default {
  data() {
    return {
      supplierList:[],
      //分页，查询
      receiptList: [],
      query: {
        dateRange: [],
        receiptOrderNo: "",
        supplierName: "",
        updateBy: "",
        currentPage: 1,//当前页
        pageSize: 5,//每次显示的条数
      },
      pageInfo: {
        total: 0,
        pageSizes: [5, 10, 20, 50]
      },

      //编辑操作
      supplierList:[],

    };
  },
  methods: {

    //-------------------------加载供应商-------------------------
    loadSuppliers() {
      this.$axios.post("/suppliers/queryAll", this.query).then((res) => {
        this.supplierList = res.data.data.list; //返回当前页数据
      });
    },
    //--------------------------删除--------------------------------------
    handleDelete(id) {
      this.$axios.delete("/wmsreceiptorder/" + id).then((res) => {
        if (res.data.code == 200) {
          this.$message.success(res.data.message);
          this.loadReceipts(); //重新加载数据
        } else {
          this.$message.error(res.data.message);
        }
      });
    },

    //--------------------------分页--------------------------------------
    //当每页显示条数改变时
    handleSizeChange(size) {
      this.query.pageSize = size;
      this.loadReceipts();
    },
    //当页数改变时
    handleCurrentChange(currentPage) {
      this.query.currentPage = currentPage;
      this.loadReceipts();
    },
    loadReceipts() {
      this.$axios.post("/wmsreceiptorder/queryAll", this.query).then((res) => {
        this.receiptList = res.data.data.list; //返回当前页数据
        this.pageInfo.total = res.data.data.total; //返回一共有多少条数据
      });
    },
    loadSupplier() {
      this.$axios.post("/wmsreceiptorder/queryAll", this.query).then((res) => {
        this.receiptList = res.data.data.list; //返回当前页数据
      });
    },

  },
  mounted() {
    //开始的时候加载页面
    this.loadReceipts();
    this.loadSupplier();
  }
};
</script>